package edu.rit.varapp.datalayer;

import java.util.HashMap;

import static edu.rit.varapp.utilities.StringUtils.*;

/**
 * Represents the modules table in the database.
 */
public class Module {

    private int EntityId;
    private int SerialNumber;
    private String LicenseCode;
    private String Location;
    private String SupportExpDate;
    private Integer Desktops;
    private Integer Readers;
    private Integer Verifiers;
    private Integer Designers;
    private Integer ScanStations;
    private Integer RemoteCaptureStations;
    private Integer amps;
    private Boolean eform;
    private Boolean TechSupport;
    private Boolean FirstLine;
    private String ScannerModel;
    private String Version;
    private String PurchaseDate;

    public Module( int EntityId, int SerialNumber ) {
        this.EntityId = EntityId;
        this.SerialNumber = SerialNumber;
    }

    public Module( int EntityId, int SerialNumber, String LicenseCode, String SupportExpDate ) {
        this.EntityId = EntityId;
        this.SerialNumber = SerialNumber;
        this.LicenseCode = LicenseCode;
        this.SupportExpDate = SupportExpDate;
    }

    public Module( int EntityId, String LicenseCode, String Location, String SupportExpDate, Integer Desktops,
                   Integer Readers, Integer Verifiers, Integer Designers, Integer ScanStations,
                   Integer RemoteCaptureStations, Integer amps, Boolean eform, Boolean TechSupport, Boolean FirstLine,
                   String ScannerModel, String Version, String PurchaseDate ) {
        this.EntityId = EntityId;
        this.LicenseCode = LicenseCode;
        this.Location = Location;
        this.SupportExpDate = SupportExpDate;
        this.Desktops = Desktops;
        this.Readers = Readers;
        this.Verifiers = Verifiers;
        this.Designers = Designers;
        this.ScanStations = ScanStations;
        this.RemoteCaptureStations = RemoteCaptureStations;
        this.amps = amps;
        this.eform = eform;
        this.TechSupport = TechSupport;
        this.FirstLine = FirstLine;
        this.ScannerModel = ScannerModel;
        this.Version = Version;
        this.PurchaseDate = PurchaseDate;
    }

    public Module( int EntityId, int SerialNumber, String LicenseCode, String Location, String SupportExpDate,
                   Integer Desktops, Integer Readers, Integer Verifiers, Integer Designers, Integer ScanStations,
                   Integer RemoteCaptureStations, Integer amps, Boolean eform ) {
        this.EntityId = EntityId;
        this.SerialNumber = SerialNumber;
        this.LicenseCode = LicenseCode;
        this.Location = Location;
        this.SupportExpDate = SupportExpDate;
        this.Desktops = Desktops;
        this.Readers = Readers;
        this.Verifiers = Verifiers;
        this.Designers = Designers;
        this.ScanStations = ScanStations;
        this.RemoteCaptureStations = RemoteCaptureStations;
        this.amps = amps;
        this.eform = eform;
    }

    public Module( int EntityId, int SerialNumber, String LicenseCode, String Location, String SupportExpDate,
                   Integer Desktops, Integer Readers, Integer Verifiers, Integer Designers, Integer ScanStations,
                   Integer RemoteCaptureStations, Integer amps, Boolean eform, Boolean TechSupport, Boolean FirstLine,
                   String ScannerModel, String Version, String PurchaseDate ) {
        this.EntityId = EntityId;
        this.SerialNumber = SerialNumber;
        this.LicenseCode = LicenseCode;
        this.Location = Location;
        this.SupportExpDate = SupportExpDate;
        this.Desktops = Desktops;
        this.Readers = Readers;
        this.Verifiers = Verifiers;
        this.Designers = Designers;
        this.ScanStations = ScanStations;
        this.RemoteCaptureStations = RemoteCaptureStations;
        this.amps = amps;
        this.eform = eform;
        this.TechSupport = TechSupport;
        this.FirstLine = FirstLine;
        this.ScannerModel = ScannerModel;
        this.Version = Version;
        this.PurchaseDate = PurchaseDate;
    }

    public Integer getDesigners() {
        return Designers;
    }

    public Integer getDesktops() {
        return Desktops;
    }

    public int getEntityId() {
        return EntityId;
    }

    public Boolean isFirstLine() {
        return FirstLine;
    }

    public String getLicenseCode() {
        return LicenseCode;
    }

    public String getLocation() {
        return Location;
    }

    public String getPurchaseDate() {
        return PurchaseDate;
    }

    public Integer getReaders() {
        return Readers;
    }

    public Integer getRemoteCaptureStations() {
        return RemoteCaptureStations;
    }

    public Integer getScanStations() {
        return ScanStations;
    }

    public String getScannerModel() {
        return ScannerModel;
    }

    public int getSerialNumber() {
        return SerialNumber;
    }

    public String getSupportExpDate() {
        return SupportExpDate;
    }

    public Boolean isTechSupport() {
        return TechSupport;
    }

    public Integer getVerifiers() {
        return Verifiers;
    }

    public String getVersion() {
        return Version;
    }

    public Integer getAmps() {
        return amps;
    }

    public Boolean isEform() {
        return eform;
    }

    public static String columnsToSQL() {
        return "EntityId,SerialNumber,LicenseCode,Location,"
               + "SupportExpDate,Desktops,Readers,Verifiers,"
               + "Designers,ScanStations,RemoteCaptureStations,"
               + "amps,eform,TechSupport,FirstLine,ScannerModel,"
               + "Version,PurchaseDate";
    }

    public String valuesToSQL( boolean sqlCall ) {
        if( sqlCall ) {
            return (EntityId + ", "
                    + SerialNumber + ", '"
                    + LicenseCode + "', '"
                    + Location + "', \""
                    + ((SupportExpDate == null) ? "0000-00-00" : SupportExpDate) + "\", "
                    + Desktops + ", "
                    + Readers + ", "
                    + Verifiers + ", "
                    + Designers + ", "
                    + ScanStations + ", "
                    + RemoteCaptureStations + ", "
                    + amps + ", " + eform + ", " + TechSupport + ", " + FirstLine + ", '"
                    + ScannerModel + "', '"
                    + Version + "', \""
                    + ((PurchaseDate == null) ? "0000-00-00" : PurchaseDate) + "\"").trim();
        } else {
            return (EntityId + ","
                    + SerialNumber + ","
                    + LicenseCode + ","
                    + Location + ",\""
                    + ((SupportExpDate == null) ? "0000-00-00" : SupportExpDate) + "\","
                    + Desktops + ","
                    + Readers + ","
                    + Verifiers + ","
                    + Designers + ","
                    + ScanStations + ","
                    + RemoteCaptureStations + ","
                    + amps + "," + eform + "," + TechSupport + "," + FirstLine + ","
                    + ScannerModel + ","
                    + Version + ",\""
                    + ((PurchaseDate == null) ? "0000-00-00" : PurchaseDate) + "\"").trim();
        }
    }

    @Override
    public String toString() {
        return "Module{" + "EntityId=" + EntityId
               + "SerialNumber=" + SerialNumber
               + "LicenseCode=" + LicenseCode
               + "Location=" + Location
               + "SupportExpDate=" + SupportExpDate
               + "Desktops=" + Desktops
               + "Readers=" + Readers
               + "Verifiers=" + Verifiers
               + "Designers=" + Designers
               + "ScanStations=" + ScanStations
               + "RemoteCaptureStations=" + RemoteCaptureStations
               + "amps=" + amps
               + "eform=" + eform
               + "TechSupport=" + TechSupport
               + "FirstLine=" + FirstLine
               + "ScannerModel=" + ScannerModel
               + "Version=" + Version
               + "PurchaseDate=" + PurchaseDate + '}';
    }

    public HashMap<String, String> asMap( boolean includeEntityId ) {
        HashMap<String, String> ret = new HashMap<String, String>();
        if( includeEntityId ) ret.put( "EntityId", String.valueOf( EntityId ) );
        ret.put( "SerialNumber", String.valueOf( SerialNumber ) );
        ret.put( "LicenseCode", LicenseCode );
        if( !checkNull( Location ) ) ret.put( "Location", Location );
        else ret.put( "Location", "" );
        if( !checkNull( SupportExpDate ) ) ret.put( "SupportExpDate", SupportExpDate );
        else ret.put( "SupportExpDate", null );
        if( !checkNull( Desktops ) ) ret.put( "Desktops", String.valueOf( Desktops ) );
        else ret.put( "Desktops", "0" );
        if( !checkNull( Readers ) ) ret.put( "Readers", String.valueOf( Readers ) );
        else ret.put( "Readers", "0" );
        if( !checkNull( Verifiers ) ) ret.put( "Verifiers", String.valueOf( Verifiers ) );
        else ret.put( "Verifiers", "0" );
        if( !checkNull( Designers ) ) ret.put( "Designers", String.valueOf( Designers ) );
        else ret.put( "Designers", "0" );
        if( !checkNull( ScanStations ) ) ret.put( "ScanStations", String.valueOf( ScanStations ) );
        else ret.put( "ScanStations", "0" );
        if( !checkNull( RemoteCaptureStations ) )
            ret.put( "RemoteCaptureStations", String.valueOf( RemoteCaptureStations ) );
        else
            ret.put( "RemoteCaptureStations", "0" );
        if( !checkNull( amps ) ) ret.put( "amps", String.valueOf( amps ) );
        else ret.put( "amps", "0" );
        if( !checkNull( eform ) ) ret.put( "eform", String.valueOf( eform ) );
        else ret.put( "eform", "No" );
        if( !checkNull( TechSupport ) ) ret.put( "TechSupport", String.valueOf( TechSupport ) );
        else ret.put( "TechSupport", "No" );
        if( !checkNull( FirstLine ) ) ret.put( "FirstLine", String.valueOf( FirstLine ) );
        else ret.put( "FirstLine", "No" );
        if( !checkNull( ScannerModel ) ) ret.put( "ScannerModel", ScannerModel );
        else ret.put( "ScannerModel", "" );
        if( !checkNull( Version ) ) ret.put( "Version", Version );
        else ret.put( "Version", "" );
        if( !checkNull( PurchaseDate ) ) ret.put( "PurchaseDate", PurchaseDate );
        else ret.put( "PurchaseDate", null );
        return ret;
    }
}
